package com.spsoft.vatoutinv.service.vmsdifferentialcode.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spsoft.core.utils.BeanUtils;
import com.spsoft.core.utils.SecurityUtils;
import com.spsoft.core.utils.StringUtil;
import com.spsoft.vatoutinv.entity.vmsdifferentialcode.VmsDifferentialCodeRecord;
import com.spsoft.vatoutinv.enums.CommonEnum;
import com.spsoft.vatoutinv.mapper.VmsDifferentialCodeRecordMapper;
import com.spsoft.vatoutinv.model.dto.vmsdifferentialcode.DifferentialCodeLogPageDto;
import com.spsoft.vatoutinv.model.vo.vmsdifferentialcode.DifferentialCodeLogPageVo;
import com.spsoft.vatoutinv.service.vmsdifferentialcode.VmsDifferentialCodeRecordService;
import org.springframework.stereotype.Service;

/**
 * @author wangy
 * @description 针对表【VMS_DIFFERENTIAL_CODE_RECORD(差额征税编码信息管理记录表)】的数据库操作Service实现
 * @createDate 2024-03-26 09:45:59
 */
@Service
public class VmsDifferentialCodeRecordServiceImpl extends ServiceImpl<VmsDifferentialCodeRecordMapper, VmsDifferentialCodeRecord>
        implements VmsDifferentialCodeRecordService {

    @Override
    public IPage<DifferentialCodeLogPageVo> getHistory(DifferentialCodeLogPageDto dto) {
        String deptCode = SecurityUtils.getDeptCode();
        Integer pageNo = dto.getPageNo();
        Integer pageSize = dto.getPageSize();
        LambdaQueryWrapper<VmsDifferentialCodeRecord> lq = new LambdaQueryWrapper<VmsDifferentialCodeRecord>()
                .apply(StringUtil.isNotEmpty(dto.getCreateTime().get(0)), "CREATE_TIME >= to_timestamp('" + dto.getCreateTime().get(0) + "', 'YYYY-MM-DD HH24:MI:SS')")
                .apply(StringUtil.isNotEmpty(dto.getCreateTime().get(1)), "CREATE_TIME <= to_timestamp('" + dto.getCreateTime().get(1) + "', 'YYYY-MM-DD HH24:MI:SS')")
                .like(StringUtil.isNotEmpty(dto.getCreateUsername()), VmsDifferentialCodeRecord::getCreateUsername, dto.getCreateUsername())
                .eq(StringUtil.isNotEmpty(dto.getOperateStatus()), VmsDifferentialCodeRecord::getOperateStatus, dto.getOperateStatus())
                .eq(VmsDifferentialCodeRecord::getDeptCode, deptCode)
                .orderByDesc(VmsDifferentialCodeRecord::getCreateTime);
        return page(new Page<>(pageNo, pageSize), lq).convert(item -> {
            DifferentialCodeLogPageVo vo = new DifferentialCodeLogPageVo();
            BeanUtils.copyBeanProp(vo, item);
            // 调用乐企结果为成功，不返回前端执行结果，防止operateMsg字段过长
            if (CommonEnum.LEQI_RETURN_CODE_SUCCESS.getKey().equals(item.getOperateStatus())) {
                vo.setOperateMsg(null);
            }
            return vo;
        });
    }
}




